#ifndef EXPRESSION_ENGINE_H
#define EXPRESSION_ENGINE_H

#include "../expressions/expressioncommon.h"
#include "../types/wfnettypes.h"

#include <coretypes.h>

#include <QtCore/QHash>
#include <QtCore/QSet>
#include <QtScript/QScriptEngine>

namespace core
{
class Type;
}

namespace wfnet
{
class AbstractTypeProxy;
class Binding;

class ExpressionEngine
{
public:
    typedef QString TypeProxyName;

public:
    static ExpressionEngine* getInstance();
    static void destroy();

    void registerTypeProxy(const core::TypeName& name,
        const TypeProxyName& proxyName);
    void unregisterTypeProxy(const core::TypeName& name);

    core::Type* eval(const net::Expr& expr, const Binding& binding,
        const UserVariables& variables,
        const SystemVariables& systemVariables);

    void registerProxyInstance(AbstractTypeProxy* proxy);

private:
    ExpressionEngine();
    ~ExpressionEngine();

private:
    QHash<core::TypeName, int> m_registeredProxies;
    QSet<AbstractTypeProxy* > m_proxyInstancies;

    QScriptEngine m_engine;
};

} // namespace wfnet

#endif
